#pragma once
#include "pch.h"
#include "Common.h"
#include "RigidBody.h"
#include "CollisionBody.h"
#include "Joint.h"

namespace Physics
{
    struct World : public rp3d::EventListener
    {

        void Create();

        void Update(const float &deltaTime);

        void Destory();

        glm::vec3 GetGravity() const;

        void SetGravity(const glm::vec3 &gravity);

        bool IsGravityEnabled() const;

        void SetIsGravityEnabled(bool isGravityEnabled);

        bool IsSleepingEnabled() const;

        void EnableSleeping(bool isSleepingEnabled);

        float GetSleepLinearVelocity() const;

        void SetSleepLinearVelocity(float sleepLinearVelocity);

        float GetSleepAngularVelocity() const;

        void SetSleepAngularVelocity(float sleepAngularVelocity);

        float GetTimeBeforeSleep() const;

        void SetTimeBeforeSleep(float timeBeforeSleep);

        Physics::RigidBody CreateRigidBody(const glm::vec3 &pos, const glm::quat &rot = glm::quat(1.0f, 0.0f, 0.0f, 0.0f));

        Physics::CollisionBody CreateCollisionBody(const glm::vec3 &pos, const glm::quat &rot = glm::quat(1.0f, 0.0f, 0.0f, 0.0f));

        void DestroyRigidBody(Physics::RigidBody& rb);

        void DestroyCollisionBody(Physics::CollisionBody &cb);

        void DestroyJoint(Physics::Joint &j);

    protected:
        virtual void OnContact(const rp3d::CollisionCallback::CallbackData &callbackData);

    public:
        rp3d::PhysicsWorld *m_Impl;
    };
};
